package pl.edu.agh.to1.dice.logic;

public class Table {
	// fields
	Row[] tRow = new Row[19];
	int variant;

	// kostruktor

	Table(int wariant) {
		variant = wariant;
		if (variant == 0)
			tRow = new Row[19];
		else
			tRow = new Row[55];

		tRow[0] = new Row("jedynki", 0, 0);
		tRow[1] = new Row("dwojki", 0, 0);
		tRow[2] = new Row("trojki", 0, 0);
		tRow[3] = new Row("czworki", 0, 0);
		tRow[4] = new Row("piatki", 0, 0);
		tRow[5] = new Row("szostki", 0, 0);
		tRow[6] = new Row("premia", 0, 0, true);
		tRow[7] = new Row("suma", 0, 0, true);
		tRow[8] = new Row("3 jednakowe", 0, 0);
		tRow[9] = new Row("4 jednakowe", 0, 0);
		tRow[10] = new Row("full", 0, 0);
		tRow[11] = new Row("maly strit", 0, 0);
		tRow[12] = new Row("duzy strit", 0, 0);
		tRow[13] = new Row("general", 0, 0);
		tRow[14] = new Row("szansa", 0, 0);
		tRow[15] = new Row("nieparzyste", 0, 0);
		tRow[16] = new Row("parzyste", 0, 0);
		tRow[17] = new Row("suma", 0, 0, true);
		tRow[18] = new Row("razem", 0, 0, true);
		if (variant == 1) {
			tRow[19] = new Row("jedynki", 0, 0);
			tRow[20] = new Row("dwojki", 0, 0);
			tRow[21] = new Row("trojki", 0, 0);
			tRow[22] = new Row("czworki", 0, 0);
			tRow[23] = new Row("piatki", 0, 0);
			tRow[24] = new Row("szostki", 0, 0);
			tRow[25] = new Row("premia", 0, 0, true);
			tRow[26] = new Row("suma", 0, 0, true);
			tRow[27] = new Row("3 jednakowe", 0, 0);
			tRow[28] = new Row("4 jednakowe", 0, 0);
			tRow[29] = new Row("full", 0, 0);
			tRow[30] = new Row("maly strit", 0, 0);
			tRow[31] = new Row("duzy strit", 0, 0);
			tRow[32] = new Row("general", 0, 0);
			tRow[33] = new Row("szansa", 0, 0);
			tRow[34] = new Row("nieparzyste", 0, 0);
			tRow[35] = new Row("parzyste", 0, 0);
			tRow[36] = new Row("suma", 0, 0, true);
			tRow[37] = new Row("jedynki", 0, 0);
			tRow[38] = new Row("dwojki", 0, 0);
			tRow[39] = new Row("trojki", 0, 0);
			tRow[40] = new Row("czworki", 0, 0);
			tRow[41] = new Row("piatki", 0, 0);
			tRow[42] = new Row("szostki", 0, 0);
			tRow[43] = new Row("premia", 0, 0, true);
			tRow[44] = new Row("suma", 0, 0, true);
			tRow[45] = new Row("3 jednakowe", 0, 0);
			tRow[46] = new Row("4 jednakowe", 0, 0);
			tRow[47] = new Row("full", 0, 0);
			tRow[48] = new Row("maly strit", 0, 0);
			tRow[49] = new Row("duzy strit", 0, 0);
			tRow[50] = new Row("general", 0, 0);
			tRow[51] = new Row("szansa", 0, 0);
			tRow[52] = new Row("nieparzyste", 0, 0);
			tRow[53] = new Row("parzyste", 0, 0);
			tRow[54] = new Row("suma", 0, 0, true);
		}
	}

	boolean czyUzyte(int a) {
		return tRow[a].czyUzyte();
	}

	void zeruj() {
		for (int i = 0; i < 19; i++)
			tRow[i].zerujA();

	}

	void zmienA(int ktore, int naCo) {
		tRow[ktore].zmienA(naCo);
	}

	void zmienB(int ktore, int naCo) {
		tRow[ktore].zmienB(naCo);
	}

	int valA(int x) {
		return tRow[x].valueA;
	}

	int valB(int x) {
		return tRow[x].valueB;
	}

	void uzyj(int i) {
		tRow[i].zmienB(tRow[i].valueA);
		tRow[i].uzyte();
	}

	void wyswietl() {
		int iter;

		for (int i = 0; i < 18; i++) {
			if (i == 6 || i == 8 || i == 17 || i == 18)
				System.out.println();
			System.out.print((i + 1) + ": ");
			if (tRow[i].used()) {
				tRow[i].wyswietlB();
			} else {
				tRow[i].wyswietlA();
			}

			if (tRow[i].czyUzyte()) {
				System.out.print(" L");
			}
			if (variant == 1) {
				System.out.print("    " + (i + 20) + ": ");
				if (tRow[i + 19].used()) {
					tRow[i + 19].dispB();
				} else {
					tRow[i + 19].dispA();
				}
				if (tRow[i + 19].czyUzyte()) {
					System.out.print(" L");
				}
				System.out.print("    " + (i + 38) + ": ");
				if (tRow[i + 37].used()) {
					tRow[i + 37].dispB();
				} else {
					tRow[i + 37].dispA();
				}
				if (tRow[i + 37].czyUzyte()) {
					System.out.print(" L");
				}
			}
			System.out.println();
		}
		System.out.println();
		System.out.print("19: ");
		tRow[18].wyswietlB();
		System.out.println();
	}
}// end Table
